package com.didispace.chapter44;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

import java.io.File;

@Component
public class ApplicationStartedEventListener implements ApplicationListener<ApplicationStartedEvent> {
    @Value("${file.upload.path}")
    private String path;

    @Override
    public void onApplicationEvent(ApplicationStartedEvent event) {
        File file = new File(path);
        if (!file.exists()) {
            file.mkdirs();
        }
    }
}
